home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-25 | 12.3 KB | 1,455 lines |
- # 1 "getopt.c"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 1 "/usr/include/stdio.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 1 "/usr/include/sys/cdefs.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 82 "/usr/include/sys/cdefs.h" 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 43 "/usr/include/stdio.h" 2 3
-
-
- # 1 "/usr/include/machine/ansi.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 45 "/usr/include/stdio.h" 2 3
-
-
- typedef unsigned int size_t;
-
-
-
-
-
-
-
- typedef long fpos_t;
-
-
-
-
-
-
-
-
-
-
- struct __sbuf {
- unsigned char *_base;
- int _size;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- typedef struct __sFILE {
- unsigned char *_p;
- int _r;
- int _w;
- short _flags;
- short _file;
- struct __sbuf _bf;
- int _lbfsize;
-
-
- void *_cookie;
- int (*_close) (void *) ;
- int (*_read) (void *, char *, int) ;
- fpos_t (*_seek) (void *, fpos_t, int) ;
- int (*_write) (void *, const char *, int) ;
-
-
- struct __sbuf _ub;
- unsigned char *_up;
- int _ur;
-
-
- unsigned char _ubuf[3];
- unsigned char _nbuf[1];
-
-
- struct __sbuf _lb;
-
-
- int _blksize;
- int _offset;
- } FILE;
-
-
- extern FILE __sF[];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void clearerr (FILE *) ;
- int fclose (FILE *) ;
- int feof (FILE *) ;
- int ferror (FILE *) ;
- int fflush (FILE *) ;
- int fgetc (FILE *) ;
- int fgetpos (FILE *, fpos_t *) ;
- char *fgets (char *, size_t, FILE *) ;
- FILE *fopen (const char *, const char *) ;
- int fprintf (FILE *, const char *, ...) ;
- int fputc (int, FILE *) ;
- int fputs (const char *, FILE *) ;
- size_t fread (void *, size_t, size_t, FILE *) ;
- FILE *freopen (const char *, const char *, FILE *) ;
- int fscanf (FILE *, const char *, ...) ;
- int fseek (FILE *, long, int) ;
- int fsetpos (FILE *, const fpos_t *) ;
- long ftell (const FILE *) ;
- size_t fwrite (const void *, size_t, size_t, FILE *) ;
- int getc (FILE *) ;
- int getchar (void) ;
- char *gets (char *) ;
-
- extern int sys_nerr;
- extern const char *const sys_errlist[];
-
- void perror (const char *) ;
- int printf (const char *, ...) ;
- int putc (int, FILE *) ;
- int putchar (int) ;
- int puts (const char *) ;
- int remove (const char *) ;
- int rename (const char *, const char *) ;
- void rewind (FILE *) ;
- int scanf (const char *, ...) ;
- void setbuf (FILE *, char *) ;
- int setvbuf (FILE *, char *, int, size_t) ;
- int sprintf (char *, const char *, ...) ;
- int sscanf (const char *, const char *, ...) ;
- FILE *tmpfile (void) ;
- char *tmpnam (char *) ;
- int ungetc (int, FILE *) ;
- int vfprintf (FILE *, const char *, char * ) ;
- int vprintf (const char *, char * ) ;
- int vsprintf (char *, const char *, char * ) ;
-
-
-
-
-
-
-
-
-
-
- char *ctermid (char *) ;
- char *cuserid (char *) ;
- FILE *fdopen (int, const char *) ;
- int fileno (FILE *) ;
-
-
-
-
-
-
-
-
- char *fgetline (FILE *, size_t *) ;
- int fpurge (FILE *) ;
- int getw (FILE *) ;
- int pclose (FILE *) ;
- FILE *popen (const char *, const char *) ;
- int putw (int, FILE *) ;
- void setbuffer (FILE *, char *, int) ;
- int setlinebuf (FILE *) ;
- char *tempnam (const char *, const char *) ;
- int snprintf (char *, size_t, const char *, ...)
- __attribute__((format (printf, 3, 4)));
- int vsnprintf (char *, size_t, const char *, char * )
- __attribute__((format (printf, 3, 0)));
- int vscanf (const char *, char * )
- __attribute__((format (scanf, 1, 0)));
- int vsscanf (const char *, const char *, char * )
- __attribute__((format (scanf, 2, 0)));
-
-
-
-
-
-
-
-
-
-
-
-
-
- FILE *funopen (const void *,
- int (*)(void *, char *, int),
- int (*)(void *, const char *, int),
- fpos_t (*)(void *, fpos_t, int),
- int (*)(void *)) ;
-
-
-
-
-
-
-
-
-
- int __srget (FILE *) ;
- int __svfscanf (FILE *, const char *, char * ) ;
- int __swbuf (int, FILE *) ;
-
-
-
-
-
-
-
-
- static __inline int __sputc(int _c, FILE *_p) {
- if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
- return (*_p->_p++ = _c);
- else
- return (__swbuf(_c, _p));
- }
- # 337 "/usr/include/stdio.h" 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 38 "getopt.c" 2
-
- # 1 "tailor.h" 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 65 "tailor.h"
-
-
-
-
- # 109 "tailor.h"
-
-
- # 130 "tailor.h"
-
-
- # 144 "tailor.h"
-
-
-
-
-
-
-
-
-
- # 172 "tailor.h"
-
-
- # 194 "tailor.h"
-
-
- # 215 "tailor.h"
-
-
- # 230 "tailor.h"
-
-
- # 250 "tailor.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 39 "getopt.c" 2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 1 "getopt.h" 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern char *optarg;
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern int optind;
-
-
-
-
- extern int opterr;
-
-
-
- extern int optopt;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- struct option
- {
-
- const char *name;
-
-
-
-
-
- int has_arg;
- int *flag;
- int val;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern int getopt_long (int argc, char *const *argv, const char *shortopts,
- const struct option *longopts, int *longind);
- extern int getopt_long_only (int argc, char *const *argv,
- const char *shortopts,
- const struct option *longopts, int *longind);
-
-
- extern int _getopt_internal (int argc, char *const *argv,
- const char *shortopts,
- const struct option *longopts, int *longind,
- int long_only);
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 79 "getopt.c" 2
-
-
-
-
-
-
-
-
- char *optarg = 0;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int optind = 0;
-
-
-
-
-
-
-
-
- static char *nextchar;
-
-
-
-
- int opterr = 1;
-
-
-
-
-
-
- int optopt = '\0' ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- static enum
- {
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
- } ordering;
-
- # 167 "getopt.c"
-
-
-
-
-
-
- extern char *getenv(const char *name);
- extern int strcmp (const char *s1, const char *s2);
- extern int strncmp(const char *s1, const char *s2, int n);
-
- static int my_strlen(const char *s);
- static char *my_index (const char *str, int chr);
-
-
-
-
- static int
- my_strlen (str)
- const char *str;
- {
- int n = 0;
- while (*str++)
- n++;
- return n;
- }
-
- static char *
- my_index (str, chr)
- const char *str;
- int chr;
- {
- while (*str)
- {
- if (*str == chr)
- return (char *) str;
- str++;
- }
- return 0;
- }
-
-
-
-
-
-
-
-
-
- static int first_nonopt;
- static int last_nonopt;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- static void exchange (char **argv);
-
-
- static void
- exchange (argv)
- char **argv;
- {
- char *temp, **first, **last;
-
-
- first = &argv[first_nonopt];
- last = &argv[optind-1];
- while (first < last) {
- temp = *first; *first = *last; *last = temp; first++; last--;
- }
-
- first = &argv[first_nonopt];
- first_nonopt += (optind - last_nonopt);
- last = &argv[first_nonopt - 1];
- while (first < last) {
- temp = *first; *first = *last; *last = temp; first++; last--;
- }
-
-
- first = &argv[first_nonopt];
- last_nonopt = optind;
- last = &argv[last_nonopt-1];
- while (first < last) {
- temp = *first; *first = *last; *last = temp; first++; last--;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int
- _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
- int argc;
- char *const *argv;
- const char *optstring;
- const struct option *longopts;
- int *longind;
- int long_only;
- {
- int option_index;
-
- optarg = 0;
-
-
-
-
-
-
- if (optind == 0)
- {
- first_nonopt = last_nonopt = optind = 1;
-
- nextchar = 0 ;
-
-
-
- if (optstring[0] == '-')
- {
- ordering = RETURN_IN_ORDER;
- ++optstring;
- }
- else if (optstring[0] == '+')
- {
- ordering = REQUIRE_ORDER;
- ++optstring;
- }
- else if (getenv ("POSIXLY_CORRECT") != 0 )
- ordering = REQUIRE_ORDER;
- else
- ordering = PERMUTE;
- }
-
- if (nextchar == 0 || *nextchar == '\0')
- {
- if (ordering == PERMUTE)
- {
-
-
-
- if (first_nonopt != last_nonopt && last_nonopt != optind)
- exchange ((char **) argv);
- else if (last_nonopt != optind)
- first_nonopt = optind;
-
-
-
-
- while (optind < argc
- && (argv[optind][0] != '-' || argv[optind][1] == '\0')
-
-
-
-
- )
- optind++;
- last_nonopt = optind;
- }
-
-
-
-
-
-
- if (optind != argc && !strcmp (argv[optind], "--"))
- {
- optind++;
-
- if (first_nonopt != last_nonopt && last_nonopt != optind)
- exchange ((char **) argv);
- else if (first_nonopt == last_nonopt)
- first_nonopt = optind;
- last_nonopt = argc;
-
- optind = argc;
- }
-
-
-
-
- if (optind == argc)
- {
-
-
- if (first_nonopt != last_nonopt)
- optind = first_nonopt;
- return (-1) ;
- }
-
-
-
-
- if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
-
-
-
-
- )
- {
- if (ordering == REQUIRE_ORDER)
- return (-1) ;
- optarg = argv[optind++];
- return 1;
- }
-
-
-
-
- nextchar = (argv[optind] + 1
- + (longopts != 0 && argv[optind][1] == '-'));
- }
-
- if (longopts != 0
- && ((argv[optind][0] == '-'
- && (argv[optind][1] == '-' || long_only))
-
-
-
- ))
- {
- const struct option *p;
- char *s = nextchar;
- int exact = 0;
- int ambig = 0;
- const struct option *pfound = 0 ;
- int indfound = 0;
-
- while (*s && *s != '=')
- s++;
-
-
- for (p = longopts, option_index = 0; p->name;
- p++, option_index++)
- if (!strncmp (p->name, nextchar, s - nextchar))
- {
- if (s - nextchar == my_strlen (p->name))
- {
-
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- }
- else if (pfound == 0 )
- {
-
- pfound = p;
- indfound = option_index;
- }
- else
-
- ambig = 1;
- }
-
- if (ambig && !exact)
- {
- if (opterr)
- fprintf ((&__sF[2]) , "%s: option `%s' is ambiguous\n",
- argv[0], argv[optind]);
- nextchar += my_strlen (nextchar);
- optind++;
- return '\0' ;
- }
-
- if (pfound != 0 )
- {
- option_index = indfound;
- optind++;
- if (*s)
- {
-
-
- if (pfound->has_arg)
- optarg = s + 1;
- else
- {
- if (opterr)
- {
- if (argv[optind - 1][1] == '-')
-
- fprintf ((&__sF[2]) ,
- "%s: option `--%s' doesn't allow an argument\n",
- argv[0], pfound->name);
- else
-
- fprintf ((&__sF[2]) ,
- "%s: option `%c%s' doesn't allow an argument\n",
- argv[0], argv[optind - 1][0], pfound->name);
- }
- nextchar += my_strlen (nextchar);
- return '\0' ;
- }
- }
- else if (pfound->has_arg == 1)
- {
- if (optind < argc)
- optarg = argv[optind++];
- else
- {
- if (opterr)
- fprintf ((&__sF[2]) , "%s: option `%s' requires an argument\n",
- argv[0], argv[optind - 1]);
- nextchar += my_strlen (nextchar);
- return optstring[0] == ':' ? ':' : '\0' ;
- }
- }
- nextchar += my_strlen (nextchar);
- if (longind != 0 )
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
-
-
-
-
- if (!long_only || argv[optind][1] == '-'
-
-
-
- || my_index (optstring, *nextchar) == 0 )
- {
- if (opterr)
- {
- if (argv[optind][1] == '-')
-
- fprintf ((&__sF[2]) , "%s: unrecognized option `--%s'\n",
- argv[0], nextchar);
- else
-
- fprintf ((&__sF[2]) , "%s: unrecognized option `%c%s'\n",
- argv[0], argv[optind][0], nextchar);
- }
- nextchar = (char *) "";
- optind++;
- return '\0' ;
- }
- }
-
-
-
- {
- char c = *nextchar++;
- char *temp = my_index (optstring, c);
-
-
- if (*nextchar == '\0')
- ++optind;
-
- if (temp == 0 || c == ':')
- {
- if (opterr)
- {
-
-
-
-
-
-
-
-
- fprintf ((&__sF[2]) , "%s: illegal option -- %c\n", argv[0], c);
-
- }
- optopt = c;
- return '\0' ;
- }
- if (temp[1] == ':')
- {
- if (temp[2] == ':')
- {
-
- if (*nextchar != '\0')
- {
- optarg = nextchar;
- optind++;
- }
- else
- optarg = 0;
- nextchar = 0 ;
- }
- else
- {
-
- if (*nextchar != '\0')
- {
- optarg = nextchar;
-
-
- optind++;
- }
- else if (optind == argc)
- {
- if (opterr)
- {
-
-
-
-
-
- fprintf ((&__sF[2]) , "%s: option requires an argument -- %c\n",
- argv[0], c);
-
- }
- optopt = c;
- if (optstring[0] == ':')
- c = ':';
- else
- c = '\0' ;
- }
- else
-
-
- optarg = argv[optind++];
- nextchar = 0 ;
- }
- }
- return c;
- }
- }
-
- int
- getopt (argc, argv, optstring)
- int argc;
- char *const *argv;
- const char *optstring;
- {
- return _getopt_internal (argc, argv, optstring,
- (const struct option *) 0,
- (int *) 0,
- 0);
- }
-
- int
- getopt_long (argc, argv, options, long_options, opt_index)
- int argc;
- char *const *argv;
- const char *options;
- const struct option *long_options;
- int *opt_index;
- {
- return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
- }
-
-
-
- # 755 "getopt.c"
-
-